/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var fieldLabel = new Array('供电局', '部门分县局', '供电所', '测点名称', '电压类别', '测点城农网', '电压等级(kV)', '电压上限(kV)', '电压下限(kV)');
var fieldName = new Array("company", "subCompany", "shortName", "name", "pointType", "pointType2", "voltageLevelName", "upperLimit", "lowerLimit",'id','rn');
var _pageSize = 20;

var now = new Date();

var store = new Ext.data.JsonStore({
    url: "../../../servlet/system/PointLoad",
    root: 'data',
    idProperty: 'id',
    totalProperty: 'count',
    fields: fieldName,
    autoLoad: true,
    baseParams: {cmd: "5m", reportStatus: reportStatus,start:0,limit:_pageSize}
});

var centercolumnModel = new Ext.grid.ColumnModel({
    columns: [
        {header: '序号',width: 40, dataIndex: 'rn', align: 'center'},    
        {
            header: fieldLabel[0],
            width: 100,
            dataIndex: fieldName[0],
            align: 'center'
        },
        {
            header: fieldLabel[1],
            width: 100,
            dataIndex: fieldName[1],
            align: 'center'
        },
        {
            header: fieldLabel[2],
            width: 100,
            dataIndex: fieldName[2],
            align: 'center'
        },
        {
            header: fieldLabel[3],
            width: 100,
            dataIndex: fieldName[3],
            align: 'center'
        },
        {
            header: fieldLabel[4],
            width: 100,
            dataIndex: fieldName[4],
            align: 'center'
        },
        {
            header: fieldLabel[5],
            width: 100,
            dataIndex: fieldName[5],
            align: 'center'
        },
        {
            header: fieldLabel[6],
            width: 100,
            dataIndex: fieldName[6],
            align: 'center'
        },
        {
            header: fieldLabel[7],
            width: 100,
            dataIndex: fieldName[7],
            align: 'center'
        },
        {
            header: fieldLabel[8],
            width: 100,
            dataIndex: fieldName[8],
            align: 'center'
        }
    ],
    defaultSortable: true
});

var centergrid = new Ext.grid.GridPanel({
    title: '监测点列表',
    store: store,
    colModel: centercolumnModel,
    region: 'center',
    width: '65%',
    split:true,
    enableColumnMove: false,
    viewConfig: {
        forceFit: true
    },
    loadMask: true,
    tbar: new Ext.Toolbar([
        pointTypeCombo, pointType2Combo, rangeCombo,reportCombo,
                , pointText, searchButton
    ]),
    bbar: new Ext.PagingToolbar({
        pageSize: _pageSize,
        store: store,
        displayInfo: true,
        displayMsg: '显示记录：{0} - {1}   总记录：{2}',
        emptyMsg: '目前没有信息'
    }),
    listeners:{
        rowclick:function( c, rowIndex, e){
            eaststore.baseParams.pointId = store.getAt(rowIndex).get("id");
            eaststore.reload();
        }
    }
});


var fieldLabel1 = new Array('时间', '电压值(kV)');
var fieldName1 = new Array("dataTime", "voltage","rn");
var eastpageSize = 20;


var eaststore = new Ext.data.JsonStore({
    url: "../../../servlet/data/M5Load",
    root: 'data',
    idProperty: 'id',
    totalProperty: 'count',
    fields: fieldName1,
    baseParams:{cmd:"general",dateTo:now.format("Y-m-d"),start:0,limit:_pageSize}
});

var eastcolumnModel = new Ext.grid.ColumnModel({
    columns: [
        {header: '序号',width: 40, dataIndex: 'rn', align: 'center'},
        {
            header: fieldLabel1[0],
            width: 100,
            dataIndex: fieldName1[0],
            align: 'center'
        },
        {
            header: fieldLabel1[1],
            width: 100,
            dataIndex: fieldName1[1],
            align: 'center'
        }
    ],
    defaultSortable: true
});

var now = new Date();
var beginDate = now.format('Y-m-d');
var dateFrom = {
    xtype: 'datefield',
    id: 'DateFrom',
    format: 'Y年m月d日',
    width: 150,
    value: now,
    listeners: {
        select: function(c, date) {            
            eaststore.baseParams.dateTo = date.format('Y-m-d');
        }
    }
};

var eastgrid = new Ext.grid.GridPanel({
    title: '详细电压列表',
    store: eaststore,
    colModel: eastcolumnModel,
    region: 'east',
    enableColumnMove: false,
    width: '35%',
    viewConfig: {
        forceFit: true
    },
    loadMask: true,
    tbar: new Ext.Toolbar([        
        dateFrom,
        {
            xtype: 'button',
            text: '搜索',
            iconCls: 'icon-search',
            width: 60,
            style: {marginLeft: '20px'},
            handler: function() {                
                eaststore.reload();
            }
        },
        '-',
        {
            xtype: 'button',
            text: '导出',
            iconCls: 'icon-excel',
            width: 60,
            style: {
                marginLeft: '20px'
            },
            handler: downloadExcel
        }
    ]),
    bbar: new Ext.PagingToolbar({
        pageSize: eastpageSize,
        store: eaststore,
        displayInfo: true,
        displayMsg: '显示记录：{0} - {1}   总记录：{2}',
        emptyMsg: '目前没有信息'
    })
});

function downloadExcel() {
    var datefrom = Ext.getCmp("DateFrom").getValue().format("Y-m-d");
    params = {
        datefrom: datefrom
    };
    var encodeParams = Ext.urlEncode(params);
    open('../../servlet/ExcelFileCreate?' + encodeParams);
}

function buildWindow() {
    var applicationUI = new Ext.Viewport({
        layout: 'fit',
        items: [
            new Ext.Panel({
                title: '5分钟电压统计表',
                //width: '100%',
                layout: 'border',
                //region: 'center',                
                items: [centergrid, eastgrid]
            })
        ]
    });
}
Ext.onReady(buildWindow);
